﻿using System;

namespace Alserve.Ffl
{

    public class LeagueTableItem : IComparable
    {
        public LeagueTableItem()
        {

        }

        private Int32 _leaguePosition;
        private Int32 _clubId = 0;
        private String _clubName;
        private Int32 _homePlayed = 0;
        private Int32 _homeWon = 0;
        private Int32 _homeDrawn = 0;
        private Int32 _homeLost = 0;
        private Int32 _homeGoalsFor = 0;
        private Int32 _homeGoalsAgainst = 0;
        private Int32 _awayPlayed = 0;
        private Int32 _awayWon = 0;
        private Int32 _awayDrawn = 0;
        private Int32 _awayLost = 0;
        private Int32 _awayGoalsFor = 0;
        private Int32 _awayGoalsAgainst = 0;
        private Int32 _points = 0;

        public Int32 LeaguePosition
        {
            get { return _leaguePosition; }
            set { _leaguePosition = value; }
        }

        public Int32 ClubId
        {
            get { return _clubId; }
            set { _clubId = value; }
        }

        public String ClubName
        {
            get { return _clubName; }
            set { _clubName = value; }
        }

        public Int32 Played
        {
            get { return _homePlayed + _awayPlayed; }
        }

        public Int32 Won
        {
            get { return _homeWon + _awayWon; }
        }

        public Int32 Drawn
        {
            get { return _homeDrawn + _awayDrawn; }
        }

        public Int32 Lost
        {
            get { return _homeLost + _awayLost; }
        }

        public Int32 GoalsFor
        {
            get { return _homeGoalsFor + _awayGoalsFor; }
        }

        public Int32 GoalsAgainst
        {
            get { return _homeGoalsAgainst + _awayGoalsAgainst; }
        }

        public Int32 HomePlayed
        {
            get { return _homePlayed; }
            set { _homePlayed = value; }
        }

        public Int32 HomeWon
        {
            get { return _homeWon; }
            set { _homeWon = value; }
        }

        public Int32 HomeDrawn
        {
            get { return _homeDrawn; }
            set { _homeDrawn = value; }
        }

        public Int32 HomeLost
        {
            get { return _homeLost; }
            set { _homeLost = value; }
        }

        public Int32 HomeGoalsFor
        {
            get { return _homeGoalsFor; }
            set { _homeGoalsFor = value; }
        }

        public Int32 HomeGoalsAgainst
        {
            get { return _homeGoalsAgainst; }
            set { _homeGoalsAgainst = value; }
        }

        public Int32 AwayPlayed
        {
            get { return _awayPlayed; }
            set { _awayPlayed = value; }
        }

        public Int32 AwayWon
        {
            get { return _awayWon; }
            set { _awayWon = value; }
        }

        public Int32 AwayDrawn
        {
            get { return _awayDrawn; }
            set { _awayDrawn = value; }
        }

        public Int32 AwayLost
        {
            get { return _awayLost; }
            set { _awayLost = value; }
        }

        public Int32 AwayGoalsFor
        {
            get { return _awayGoalsFor; }
            set { _awayGoalsFor = value; }
        }

        public Int32 AwayGoalsAgainst
        {
            get { return _awayGoalsAgainst; }
            set { _awayGoalsAgainst = value; }
        }

        public Int32 Points
        {
            get { return _points; }
            set { _points = value; }
        }

        public int CompareTo(object obj)
        {
            
            LeagueTableItem clubItem = (LeagueTableItem)obj;
            
            if (this.Points == clubItem.Points)
            {
                if (this.HomeGoalsFor + this.AwayGoalsFor - this.HomeGoalsAgainst - this.AwayGoalsAgainst == clubItem.HomeGoalsFor + clubItem.AwayGoalsFor - clubItem.HomeGoalsAgainst - clubItem.AwayGoalsAgainst)
                {
                    if (this.HomeGoalsFor + this.AwayGoalsFor == clubItem.HomeGoalsFor + clubItem.AwayGoalsFor)
                    {
                        return this.ClubName.CompareTo(clubItem.ClubName);
                    }
                    else
                    {
                        return -(this.HomeGoalsFor + this.AwayGoalsFor).CompareTo(clubItem.HomeGoalsFor + clubItem.AwayGoalsFor);
                    }
                }
                else
                {
                    return -(this.HomeGoalsFor + this.AwayGoalsFor - this.HomeGoalsAgainst - this.AwayGoalsAgainst).CompareTo(clubItem.HomeGoalsFor + clubItem.AwayGoalsFor - clubItem.HomeGoalsAgainst - clubItem.AwayGoalsAgainst);
                }
            }
            else
            {
                return -(this.Points.CompareTo(clubItem.Points));
            }

        }
    }
}